package com.syq.dao;

import com.syq.pojo.SysUserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * @author Sun Yueqi
 * @version 1.00
 * @time 2022/5/25 20:42
 */
public interface SysUserMapper {

    @Select("select * from sys_user_info where username=#{username}")
    SysUserInfo findByName(String username);

    @Select("select * from sys_user_info where email=#{email}")
    SysUserInfo findByEmail(String email);

    @Select("select * from sys_user_info where phone=#{phone}")
    SysUserInfo findByPhone(String phone);

    @Insert("INSERT INTO sys_user_info (username,password,pwd_salt,`name`,phone,email,sex,avator,info,`type`,status,create_time,create_by,remark) VALUES(#{username},#{password},#{pwdSalt},#{name},#{phone},#{email},#{sex},#{avator},#{info},#{type},#{status},#{createTime},#{createBy},#{remark})")
    void addUser(SysUserInfo sysUserInfo);

    @Update("UPDATE sys_user_info SET last_login= current_login, current_login=#{loginDate},last_login_ip=current_login_ip,current_login_ip=#{ip} WHERE username=#{username}")
    void updateLogin(@Param("username") String userName, @Param("loginDate") Date loginDate, @Param("ip") String ip);
}
